package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.entity.Feedback;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.FeedbackService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.AddFeedbackVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 意见反馈表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:08
 */
@Api(tags = "意见反馈相关")
@RestController
@RequestMapping("/api/feedback")
public class FeedbackController {

    @Resource
    private LoginUtil loginUtil;
    @Resource
    private FeedbackService feedbackService;

    @ApiOperation(value = "新增意见反馈")
    @PostMapping("addFeedback")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> addFeedback(@RequestBody AddFeedbackVo addVo) {
        User user = loginUtil.getUser();
        return feedbackService.addFeedback(user.getId(), addVo);
    }

    @ApiOperation(value = "查询意见反馈列表")
    @GetMapping("selectFeedbackList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<Feedback>> selectFeedbackList(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        User user = loginUtil.getUser();
        return ApiRestResponse.success(PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->feedbackService.list(new LambdaQueryWrapper<Feedback>()
                .eq(Feedback::getUserId, user.getId())
                .orderByDesc(Feedback::getCreateTime))));
    }
}
